﻿#include "Camera.h"
#include <math.h>

CCamera::CCamera()
{
	viewport.x = 0;
	viewport.y = G_ScreenHeight;
}

D3DXVECTOR2 CCamera::Transform(int x, int y)
{
	D3DXMATRIX matrix;
	D3DXMatrixIdentity (&matrix);
	matrix._22 = -1;
	matrix._41 = -viewport.x;
	matrix._42 = viewport.y;

	D3DXVECTOR3 pos3(x ,y ,1);	//tao ma tran 3 gan tao do mario vao
	D3DXVECTOR4 MatrixResult;
	D3DXVec3Transform (&MatrixResult,&pos3,&matrix);
	//Kết thúc transform

	D3DXVECTOR2 result = D3DXVECTOR2 (MatrixResult.x,MatrixResult.y);
	return result;
}

D3DXVECTOR3 CCamera::CenterSprite(int x, int y)
{
	D3DXVECTOR3 pCenter = D3DXVECTOR3(x/2, y/2, 0);
	return pCenter;
}

void CCamera::UpdateCamera(int x, int deltaTime)
{
	viewport.x = x - 400;
	if (viewport.x < 0)
		viewport.x = 0;
}